package com.isorf.controller;

import com.github.pagehelper.PageInfo;
import com.isorf.pojo.Shoe;
import com.isorf.service.ShoeService;
import com.isorf.util.ResponseResult;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@Api(tags = "鞋子管理")
@RestController
@RequestMapping("/shoe")
public class ShoeController {
    @Autowired
    private ShoeService shoeService;

    /**
     * 新增鞋子
     */
    @PostMapping("/add")
    public ResponseResult<Boolean> addShoe(@RequestBody Shoe shoe) {
        Boolean result = shoeService.addShoe(shoe);
        if (result) {
            return ResponseResult.success(ResponseResult.SUCCESS, "添加成功", result);
        } else {
            return ResponseResult.failure(ResponseResult.FAILED, "添加失败");
        }
    }

    /**
     * 删除鞋子
     */
    @PostMapping("/delete")
    public ResponseResult<Boolean> deleteShoe(@RequestParam int shoeId) {
        Boolean result = shoeService.deleteShoe(shoeId);
        if (result) {
            return ResponseResult.success(ResponseResult.SUCCESS, "删除成功", result);
        } else {
            return ResponseResult.failure(ResponseResult.FAILED, "删除失败");
        }
    }

    /**
     * 更新鞋子
     */
    @PostMapping("/update")
    public ResponseResult<Boolean> updateShoe(@RequestBody Shoe shoe) {
        Boolean result = shoeService.updateShoe(shoe);
        if (result) {
            return ResponseResult.success(ResponseResult.SUCCESS, "更新成功", result);
        } else {
            return ResponseResult.failure(ResponseResult.FAILED, "更新失败");
        }
    }

    /**
     * 根据ID查询鞋子
     */
    @GetMapping("/getById")
    public ResponseResult<Shoe> getShoeById(@RequestParam int shoeId) {
        Shoe result = shoeService.getShoeById(shoeId);
        if (result != null) {
            return ResponseResult.success(ResponseResult.SUCCESS, "查询成功", result);
        } else {
            return ResponseResult.failure(ResponseResult.FAILED, "查询失败");
        }
    }

    /**
     * 分页查询鞋子
     */
    @GetMapping("/pageList")
    public ResponseResult<PageInfo<Shoe>> pageList(@RequestParam(defaultValue = "1") int pageNum, 
                                                   @RequestParam(defaultValue = "5") int pageSize) {
        PageInfo<Shoe> result = shoeService.pageList(pageNum, pageSize);
        if (result != null && result.getList().size() > 0) {
            return ResponseResult.success(ResponseResult.SUCCESS, "查询成功", result);
        } else {
            return ResponseResult.failure(ResponseResult.FAILED, "查询失败");
        }
    }
} 